package com.heima.homeservicemanagementsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.homeservicemanagementsystem.mapper.SysPermissionMapper;
import com.heima.homeservicemanagementsystem.entity.SysPermission;
import com.heima.homeservicemanagementsystem.service.SysPermissionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 权限表(SysPermission)表服务实现类
 *
 * @author makejava
 * @since 2025-02-27 20:08:49
 */
@Service("sysPermissionService")
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements SysPermissionService {

    @Override
    public void tree(List<SysPermission> records) {
        for (SysPermission record : records) {
            LambdaQueryWrapper<SysPermission> lwq = new LambdaQueryWrapper<>();
            lwq.eq(SysPermission::getParentId, record.getId());
            lwq.orderByAsc(SysPermission::getSort);
            List<SysPermission> list = super.list(lwq);
            if (!list.isEmpty()) {
                record.setChildren(list);

                tree(list);
            }
        }
    }

    @Override
    public boolean removeMeprebyId(List<String> id) {
        int removemeprebyid = baseMapper.removemeprebyid(id);
        return removemeprebyid > 0;
    }
}

